var view_timer = null;

function viewPort(userAgent, pageWidth) {
	var oView = document.getElementById('viewport');
	if(oView) {
		document.head.removeChild(oView);
	}
	if(!pageWidth) {
		pageWidth = 375;
	}
	var screen_w = parseInt(window.screen.width),
		scale = screen_w / pageWidth;
	if(/Android (\d+\.\d+)/.test(userAgent)) {
		var creat_meta = document.createElement('meta');
		creat_meta.name = 'viewport';
		creat_meta.id = 'viewport';
		var version = parseFloat(RegExp.$1);
		if(version > 2.3) {
			creat_meta.content = 'width=' + pageWidth + ', initial-scale = ' + scale + ',user-scalable=1, minimum-scale = ' + scale + ', maximum-scale = ' + scale + ', target-densitydpi=device-dpi';
		} else {
			creat_meta.content = '"width=' + pageWidth + ', target-densitydpi=device-dpi';
		}
		document.head.appendChild(creat_meta);
	} else {
		var creat_meta = document.createElement('meta');
		creat_meta.name = 'viewport';
		creat_meta.id = 'viewport';
		if(window.orientation == '-90' || window.orientation == '90') {
			scale = window.screen.height / pageWidth;
			creat_meta.content = 'width=' + pageWidth + ', initial-scale = ' + scale + ' ,minimum-scale = ' + scale + ', maximum-scale = ' + scale + ', user-scalable=no, target-densitydpi=device-dpi';
		} else {
			creat_meta.content = 'width=' + pageWidth + ', initial-scale = ' + scale + ' ,minimum-scale = ' + scale + ', maximum-scale = ' + scale + ', user-scalable=no, target-densitydpi=device-dpi';
		}
		document.head.appendChild(creat_meta);
	}
}
viewPort(navigator.userAgent);

window.onresize = function() {
	clearTimeout(view_timer);
	view_timer = setTimeout(function() {
		viewPort(navigator.userAgent);
	}, 500);
}

function nowtime() {
	var dateTime = new Date();
	var year = dateTime.getFullYear(); //获取完整的年份(4位,1970-????)
	var month = dateTime.getMonth() + 1; //获取当前月份(0-11,0代表1月)
	var day = dateTime.getDate(); //获取当前日(1-31)
	var week = dateTime.getDay(); //获取当前星期X(0-6,0代表星期天)
	var hour = dateTime.getHours(); //获取当前小时数(0-23)
	var min = dateTime.getMinutes(); //获取当前分钟数(0-59)
	var seconds = dateTime.getSeconds(); //获取当前秒数(0-59)
	if(month < 10) {
		month = "0" + month;
	}
	if(day < 10) {
		day = "0" + day;
	}
	if(hour < 10) {
		hour = "0" + hour;
	}
	if(min < 10) {
		min = "0" + min;
	}
	if(seconds < 10) {
		seconds = "0" + seconds;
	}
	return year + "-" + month + "-" + day + " " + hour + ":" + min + ":" + seconds;
}

function removeAaary(_arr, _obj) {
	var length = _arr.length;
	for(var i = 0; i < length; i++) {
		if(_arr[i] == _obj) {
			if(i == 0) {
				_arr.shift(); //删除并返回数组的第一个元素
				return _arr;
			} else if(i == length - 1) {
				_arr.pop(); //删除并返回数组的最后一个元素
				return _arr;
			} else {
				_arr.splice(i, 1); //删除下标为i的元素
				return _arr;
			}
		}
	}
}